package com.study.heartBeat.task;

import com.study.heartBeat.listener.ServerHeartBeatListener;
import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;
import io.netty.util.concurrent.ScheduledFuture;

/**
 * @ClassName: ServerHeartBeatTask
 * @Description:
 * @Date 2024/04/30 13:38
 * @Author songshaoqiu
 **/

public class ServerHeartBeatTask implements Runnable{
    private Channel channel;

    private ScheduledFuture<?> scheduledFuture;

    public ScheduledFuture<?> getScheduledFuture() {
        return scheduledFuture;
    }

    public void setScheduledFuture(ScheduledFuture<?> scheduledFuture) {
        this.scheduledFuture = scheduledFuture;
    }

    public Channel getChannel() {
        return channel;
    }

    public ServerHeartBeatTask(Channel channel) {
        this.channel = channel;
    }

    public void setChannel(Channel channel) {
        this.channel = channel;
    }

    @Override
    public void run() {
        ChannelFuture channelFuture = channel.writeAndFlush("【服务端主动发送心跳】");
        channelFuture.addListener(new ServerHeartBeatListener(channel,scheduledFuture));
    }
}
